package com.burstly.lib.conveniencelayer;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.support.v4.app.Fragment;
import com.burstly.lib.BurstlySdk;
import com.burstly.lib.currency.CurrencyManager;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@TargetApi(9)
public class Burstly
{
  private static final Map<Activity, List<IActivityListener>> ACTIVITY_LISTENERS = new HashMap();
  private static final Map<Fragment, List<IFragmentListener>> FRAGMENT_LISTENERS = new HashMap();
  public static final String TAG = "Burstly Convenience Layer";
  private static final Map<String, String> VIEW_MAP = new HashMap();
  private static String sAppID;
  private static Context sContext;
  private static CurrencyManager sCurrencyManager;
  private static String sDeviceId;
  private static String[] sIntegrationDeviceIDs;
  private static boolean sIntegrationModeEnabled = false;
  private static BurstlyIntegrationModeAdNetworks sIntegrationNetwork = BurstlyIntegrationModeAdNetworks.HOUSE;
  protected static boolean sIsInitialized = false;
  static LoggerExt sLog;
  private static boolean sLoggingEnabled;
  private static boolean sTestModeAlertShown = false;

  public static void addActivityListener(Activity paramActivity, IActivityListener paramIActivityListener)
  {
    if ((paramIActivityListener instanceof BurstlyBaseAd))
    {
      BurstlyBaseAd localBurstlyBaseAd = (BurstlyBaseAd)paramIActivityListener;
      String str1 = localBurstlyBaseAd.getName();
      String str2 = localBurstlyBaseAd.getAppId() + ":" + localBurstlyBaseAd.getZoneId();
      if (VIEW_MAP.containsKey(str1))
      {
        if (!((String)VIEW_MAP.get(str1)).equals(str2))
          throw new RuntimeException("Attempting to reuse the view Id " + str1 + " with a different app/zone combination.  Use a new view Id for each pub and zone");
      }
      else
        VIEW_MAP.put(str1, str2);
    }
    if (ACTIVITY_LISTENERS.containsKey(paramActivity))
    {
      ((List)ACTIVITY_LISTENERS.get(paramActivity)).add(paramIActivityListener);
      return;
    }
    ArrayList localArrayList = new ArrayList();
    localArrayList.add(paramIActivityListener);
    ACTIVITY_LISTENERS.put(paramActivity, localArrayList);
  }

  public static void addFragmentListener(Fragment paramFragment, IFragmentListener paramIFragmentListener)
  {
    if ((paramIFragmentListener instanceof BurstlyBaseAd))
    {
      BurstlyBaseAd localBurstlyBaseAd = (BurstlyBaseAd)paramIFragmentListener;
      String str1 = localBurstlyBaseAd.getName();
      String str2 = localBurstlyBaseAd.getAppId() + ":" + localBurstlyBaseAd.getZoneId();
      if (VIEW_MAP.containsKey(str1))
      {
        if (!((String)VIEW_MAP.get(str1)).equals(str2))
          throw new RuntimeException("Attempting to reuse the view Id " + str1 + " with a different app/zone combination.  Use a new view Id for each pub and zone");
      }
      else
        VIEW_MAP.put(str1, str2);
    }
    if (FRAGMENT_LISTENERS.containsKey(paramFragment))
    {
      ((List)FRAGMENT_LISTENERS.get(paramFragment)).add(paramIFragmentListener);
      return;
    }
    ArrayList localArrayList = new ArrayList();
    localArrayList.add(paramIFragmentListener);
    FRAGMENT_LISTENERS.put(paramFragment, localArrayList);
  }

  public static void deinit()
  {
    if (!sIsInitialized)
    {
      sLog.logWarning("Burstly Convenience Layer", "Burstly already deinitialized or never's been initialized before.", new Object[0]);
      return;
    }
    if (ACTIVITY_LISTENERS.size() != 0)
      sLog.logError("Burstly Convenience Layer", "Deinitializing Burstly conveniencelayer system before everything is destroyed", new Object[0]);
    BurstlySdk.shutdown(sContext);
    sIsInitialized = false;
  }

  public static void enableIntegrationMode(String[] paramArrayOfString)
  {
    if (!sIsInitialized)
      throw new RuntimeException("Burstly.init never called or Burstly.deinit already called.");
    if (paramArrayOfString != null)
      sIntegrationDeviceIDs = paramArrayOfString;
    sIntegrationModeEnabled = true;
  }

  static String getAppID()
  {
    if (!sIsInitialized)
      throw new RuntimeException("Burstly.init never called or Burstly.deinit already called.");
    return sAppID;
  }

  public static CurrencyManager getCurrencyManager()
  {
    if (!sIsInitialized)
      throw new RuntimeException("Burstly.init never called or Burstly.deinit already called.");
    return sCurrencyManager;
  }

  public static BurstlyIntegrationModeAdNetworks getIntegrationNetwork()
  {
    if (!sIsInitialized)
      throw new RuntimeException("Burstly.init never called or Burstly.deinit already called.");
    return sIntegrationNetwork;
  }

  public static void init(Context paramContext, String paramString)
  {
    try
    {
      if (!sIsInitialized)
      {
        sIsInitialized = true;
        sAppID = paramString;
        sContext = paramContext.getApplicationContext();
        initBurstly(paramContext);
        sIntegrationModeEnabled = false;
        sIntegrationDeviceIDs = null;
        sIntegrationNetwork = BurstlyIntegrationModeAdNetworks.HOUSE;
        sDeviceId = Utils.getRawDeviceId(paramContext);
        sCurrencyManager = new CurrencyManager();
        sCurrencyManager.initManager(sContext, sAppID);
      }
      while (true)
      {
        return;
        sLog.logWarning("Burstly Convenience Layer", "Burstly already initialized", new Object[0]);
      }
    }
    finally
    {
    }
  }

  protected static void initBurstly(Context paramContext)
  {
    BurstlySdk.init(paramContext);
    if (sLog == null)
      sLog = LoggerExt.getInstance();
    setLoggingEnabled(true);
    ACTIVITY_LISTENERS.clear();
  }

  public static boolean isIntegrationModeEnabledForThisDevice()
  {
    if (!sIsInitialized)
      throw new RuntimeException("Burstly.init never called or Burstly.deinit already called.");
    boolean bool1 = sIntegrationModeEnabled;
    boolean bool2 = false;
    if (bool1)
      if (sIntegrationDeviceIDs != null)
      {
        String str = sDeviceId;
        bool2 = false;
        if (str != null)
        {
          boolean bool3 = Arrays.asList(sIntegrationDeviceIDs).contains(sDeviceId);
          bool2 = false;
          if (!bool3);
        }
      }
      else
      {
        bool2 = true;
      }
    return bool2;
  }

  public static boolean isLoggingEnabled()
  {
    return sLoggingEnabled;
  }

  public static void onDestroyActivity(Activity paramActivity)
  {
    if (ACTIVITY_LISTENERS.containsKey(paramActivity))
    {
      List localList = (List)ACTIVITY_LISTENERS.get(paramActivity);
      for (int i = -1 + localList.size(); i >= 0; i--)
      {
        ((IActivityListener)localList.get(i)).activityDestroyed(paramActivity);
        localList.remove(i);
      }
      ACTIVITY_LISTENERS.remove(paramActivity);
    }
  }

  public static void onDestroyFragment(Fragment paramFragment)
  {
    if (FRAGMENT_LISTENERS.containsKey(paramFragment))
    {
      List localList = (List)FRAGMENT_LISTENERS.get(paramFragment);
      for (int i = -1 + localList.size(); i >= 0; i--)
      {
        ((IFragmentListener)localList.get(i)).fragmentDestroyed(paramFragment);
        localList.remove(i);
      }
      FRAGMENT_LISTENERS.remove(paramFragment);
    }
  }

  public static void onPauseActivity(Activity paramActivity)
  {
    if (ACTIVITY_LISTENERS.containsKey(paramActivity))
    {
      Iterator localIterator = ((List)ACTIVITY_LISTENERS.get(paramActivity)).iterator();
      while (localIterator.hasNext())
        ((IActivityListener)localIterator.next()).activityPaused(paramActivity);
    }
  }

  public static void onPauseFragment(Fragment paramFragment)
  {
    if (FRAGMENT_LISTENERS.containsKey(paramFragment))
    {
      Iterator localIterator = ((List)FRAGMENT_LISTENERS.get(paramFragment)).iterator();
      while (localIterator.hasNext())
        ((IFragmentListener)localIterator.next()).fragmentPaused(paramFragment);
    }
  }

  public static void onResumeActivity(Activity paramActivity)
  {
    if (ACTIVITY_LISTENERS.containsKey(paramActivity))
    {
      Iterator localIterator = ((List)ACTIVITY_LISTENERS.get(paramActivity)).iterator();
      while (localIterator.hasNext())
        ((IActivityListener)localIterator.next()).activityResumed(paramActivity);
    }
  }

  public static void onResumeFragment(Fragment paramFragment)
  {
    if (FRAGMENT_LISTENERS.containsKey(paramFragment))
    {
      Iterator localIterator = ((List)FRAGMENT_LISTENERS.get(paramFragment)).iterator();
      while (localIterator.hasNext())
        ((IFragmentListener)localIterator.next()).fragmentResumed(paramFragment);
    }
  }

  public static void removeActivityListener(Activity paramActivity, IActivityListener paramIActivityListener)
  {
    if (ACTIVITY_LISTENERS.containsKey(paramActivity))
      ((List)ACTIVITY_LISTENERS.get(paramActivity)).remove(paramIActivityListener);
  }

  public static void removeActivityListener(IActivityListener paramIActivityListener)
  {
    Iterator localIterator = ACTIVITY_LISTENERS.values().iterator();
    while (localIterator.hasNext())
      ((List)localIterator.next()).remove(paramIActivityListener);
  }

  public static void removeFragmentListener(Fragment paramFragment, IFragmentListener paramIFragmentListener)
  {
    if (FRAGMENT_LISTENERS.containsKey(paramFragment))
      ((List)FRAGMENT_LISTENERS.get(paramFragment)).remove(paramIFragmentListener);
  }

  public static void removeFragmentListener(IFragmentListener paramIFragmentListener)
  {
    if (paramIFragmentListener != null)
      FRAGMENT_LISTENERS.remove(paramIFragmentListener);
  }

  public static void setIntegrationNetwork(BurstlyIntegrationModeAdNetworks paramBurstlyIntegrationModeAdNetworks)
  {
    if (!sIsInitialized)
      throw new RuntimeException("Burstly.init never called or Burstly.deinit already called.");
    sIntegrationNetwork = paramBurstlyIntegrationModeAdNetworks;
  }

  public static void setLoggingEnabled(boolean paramBoolean)
  {
    if (paramBoolean)
      LoggerExt.setLogLevel(3);
    while (true)
    {
      sLoggingEnabled = paramBoolean;
      return;
      LoggerExt.setLogLevel(7);
    }
  }

  static void showTestModeAlert(Context paramContext)
  {
    try
    {
      if (sTestModeAlertShown != true)
      {
        AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
        localBuilder.setTitle("Burstly Integration Mode").setMessage("You will only see sample ads from specified networks on this device. Disable Integration Mode to see live ads.").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener()
        {
          public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
          {
            paramAnonymousDialogInterface.dismiss();
          }
        });
        localBuilder.create().show();
        sTestModeAlertShown = true;
      }
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.conveniencelayer.Burstly
 * JD-Core Version:    0.6.2
 */